//
//  YZMNetworkTools.swift
//  YZMweibo
//
//  Created by Simon on 16/4/20.
//  Copyright © 2016年 Simon. All rights reserved.
//

import UIKit
import AFNetworking
// 请求方式枚举
enum YZMRequestMethod: Int{
    case GET = 0
    case POST = 1
}

class YZMNetworkTools: AFHTTPSessionManager {
    
    // 网络请求全局访问点
    static let sharedTools:YZMNetworkTools = {
        let tools = YZMNetworkTools()
        tools.responseSerializer.acceptableContentTypes?.insert("text/plain")
        return tools
    }()
    
    // 网络请求方法
    func request(method:YZMRequestMethod, urlString: String, params:AnyObject?,callback:(response: AnyObject?, error:NSError?)->() ){
        if method == .GET{
            self.GET(urlString, parameters: params, progress: nil, success: { (_, response) -> Void in
                callback(response: response, error: nil)
                
                }, failure: { (_, error) -> Void in
                    callback(response: nil, error: error)
                    
            })
            // POST
        }else{
            self.POST(urlString, parameters: params, progress: nil, success: { (_, response) -> Void in
                callback(response: response, error: nil)
                
                }, failure: { (_, error) -> Void in
                    callback(response: nil, error: error)
                    
            })
        }
        
    }
    
}
